/**
 * New node file
 */
 
/* 
var mongoose= require("mongoose");

//Connect to mongo DB
//mongoose.connect('mongodb://' + "localhost" + '/mysystem');
mongoose.connect('mongodb://localhost/test'); 
var myDB = mongoose.connection;

//Error handling if conncetion fails
myDB.on('error', console.error.bind(console, 'connection error:'));
//Check if successful connection is made
myDB.once('open', function callback () {
  console.log("MY DB Connected with Mongoose");
});
 
 */
 
//.- source: http://coenraets.org/blog/2012/10/creating-a-rest-api-using-node-js-express-and-mongodb/

//.- Modelado Mongo: http://rafinguer.blogspot.com/2010/11/mongodb-consejos-sobre-diseno-de.html
//.- 				 http://www.analyticaweb.com/desarrollo-web/modelado-de-datos-con-mongodb-embebidos-vs-referenciados

//.- Cargamos el modulo para conectarnos a la base de datos en MongoDB
var mongo = require('mongodb');
 
var Server = mongo.Server,
    Db = mongo.Db,
    BSON = mongo.BSONPure;

//.- Servidor y puerto por defecto de la base de datos 
var server = new Server('localhost', 27017, {auto_reconnect: true});
//.- Agremos las base de datos a conectar--> test

var dataBase = "vitrinia";
var db1 = new Db(dataBase, server);

function openDataBase(collectionName,callback){
	
	db1.open(function(err,db){
		if(err){
			console.log("Error connect to databasessss");
			return callback(err);
		}
			
	
		var collection = new mongo.Collection(db,collectionName);
		console.log("Database conected");
		return callback(null,collection,db);
	});
	
}
exports.openDataBase = openDataBase;

//.-utilizar authentification, fuente: http://stackoverflow.com/questions/10108170/node-js-reuse-mongodb-reference






////.- Abrimos la conexion a base de datos y manejamos ante cualquier error 
//var connectionSucees = true;
//var connect = function(){
//	db.open(function(err, db) {
//	    if(!err) {
//	        console.log("Connected to "+dataBase+" database.");
//	        connectionSucees = true;
//	    }
//	    else{
//	    	console.log("Error Connected to "+dataBase+" database.");
//	    	connectionSucees = false;
//	    }
//	    return db;
//	});
//	
//	
//};
//exports.connect = connect;
//exports.connectionSucees = connectionSucees;





